package com.springboot.service.impl;

import com.springboot.mapper.ChatRecordMapper;
import com.springboot.mapper.UserLoginFormMapper;
import com.springboot.model.ChatRecord;
import com.springboot.model.UserLoginForm;
import com.springboot.service.DoctorChattingListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * 医生查看聊天列表
 */
@Service
public class DoctorChattingListServiceImpl implements DoctorChattingListService {
    @Autowired
    private UserLoginFormMapper userLoginFormMapper;
    @Autowired
    private ChatRecordMapper chatRecordMapper;

    //通过用户电话查找用户
    @Override
    public UserLoginForm findUserByTel(String userTel)
    {
        return userLoginFormMapper.selectByTel(userTel);
    }

    //通过接收方id查找该接收方的所有消息
    @Override
    public ArrayList<ChatRecord> findChatByReceiverId(Integer receiverId)
    {
        return chatRecordMapper.selectByReceiverId(receiverId);
    }

    //通过发送方id查找该发送方的所有消息
    @Override
    public ArrayList<ChatRecord> findChatBySenderId(Integer senderId)
    {
        return chatRecordMapper.selectBySenderId(senderId);
    }

    //通过接收方id和发送方id查找记录
    @Override
    public ArrayList<ChatRecord> findChatByRecord(ChatRecord chatRecord)
    {
        return chatRecordMapper.selectByRecord(chatRecord);
    }

    //通过用户id查找用户
    @Override
    public UserLoginForm findUserById(Integer userId)
    {
        return userLoginFormMapper.selectByPrimaryKey(userId);
    }

    //更新chatRecord表
    @Override
    public int updateChatRecord(ChatRecord chatRecord)
    {
        return chatRecordMapper.updateByPrimaryKeySelective(chatRecord);
    }

    //插入数据到chatRecord表中
    @Override
    public int insertChatRecord(ChatRecord chatRecord)
    {
        return chatRecordMapper.insertSelective(chatRecord);
    }
}
